package com.softeem.score.manager.controller.admin;

import com.github.pagehelper.PageInfo;
import com.softeem.score.common.log.annotation.Log;
import com.softeem.score.common.log.enums.OperatorType;
import com.softeem.score.manager.service.TeachingClassService;
import com.softeem.score.model.dto.TeachingClassDto;
import com.softeem.score.model.entity.educational.TeachingClass;
import com.softeem.score.model.vo.common.Result;
import com.softeem.score.model.vo.common.ResultCodeEnum;
import com.softeem.score.model.vo.educational.ElectiveCourseVo;
import com.softeem.score.model.vo.educational.TeachingClassVo;
import com.softeem.score.model.vo.school.MapVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "教师管理")
@RestController
@RequestMapping("/admin/educational/teachingClass")
public class TeachingClassController {
    @Autowired
    private TeachingClassService teachingClassService;


    @Operation(summary = "分页查询教学班级列表")
    @GetMapping(value = "/getTeachingClassByPage/{pageNum}/{pageSize}")
    public Result getTeachingClassByPage(@PathVariable(value = "pageNum") Integer pageNum,
                                         @PathVariable(value = "pageSize") Integer pageSize,
                                         TeachingClassDto teachingClassDto) {
        PageInfo<TeachingClassVo> pageInfo = teachingClassService.findByPage(teachingClassDto, pageNum, pageSize);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    @Log(title = "保存教学班级", businessType = 1, operatorType = OperatorType.TEACHER)
    @Operation(summary = "保存教学班级")
    @PostMapping(value = "/saveTeachingClass")
    public Result saveTeachingClass(@RequestBody TeachingClass teachingClass) {
        teachingClassService.saveTeachingClass(teachingClass);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Log(title = "更新教学班级", businessType = 2, operatorType = OperatorType.TEACHER)
    @Operation(summary = "更新教学班级")
    @PutMapping(value = "/updateTeachingClass")
    public Result updateTeachingClass(@RequestBody TeachingClass teachingClass) {
        teachingClassService.updateTeachingClass(teachingClass);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Log(title = "通过id删除教学班级", businessType = 3, operatorType = OperatorType.TEACHER)
    @Operation(summary = "通过id删除教学班级")
    @DeleteMapping(value = "/deleteById/{teachingClassId}")
    public Result deleteById(@PathVariable(value = "teachingClassId") Long teachingClassId) {
        teachingClassService.deleteById(teachingClassId);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Log(title = "通过班级id保存学生", businessType = 1, operatorType = OperatorType.TEACHER)
    @Operation(summary = "通过班级id保存学生")
    @PostMapping(value = "/saveStudentToTeachingClassByClassesId/{teachingClassId}/{classesId}")
    public Result saveStudentToTeachingClassByClassesId(@PathVariable(value = "teachingClassId") Long teachingClassId,
                                                        @PathVariable(value = "classesId") Long classesId) {
        teachingClassService.saveStudentToTeachingClassByClassesId(teachingClassId, classesId);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Log(title = "查询符合条件的行政班级", businessType = 0, operatorType = OperatorType.TEACHER)
    @Operation(summary = "查询符合条件的行政班级")
    @GetMapping(value = "/findAllClassByTeachingClass/{courseId}/{academicYear}/{semester}")
    public Result findAllClassByTeachingClass(@PathVariable(value = "courseId") Long courseId,
                                              @PathVariable(value = "academicYear") Integer academicYear,
                                              @PathVariable(value = "semester") Integer semester) {
        List<MapVo> objectMap = teachingClassService.findAllClassByTeachingClass(courseId, academicYear, semester);
        return Result.build(objectMap, ResultCodeEnum.SUCCESS);
    }

    //选课------------------------------//
    @Log(title = "分页获取选课信息", businessType = 0, operatorType = OperatorType.STUDENT)
    @Operation(summary = "分页获取选课信息")
    @GetMapping(value = "/getElectiveCourseListByPage/{pageNum}/{pageSize}")
    public Result<PageInfo<ElectiveCourseVo>> getElectiveCourseListByPage(@PathVariable(value = "pageNum") Integer pageNum,
                                                                          @PathVariable(value = "pageSize") Integer pageSize,
                                                                          @RequestParam(value = "ownership", required = false) Integer ownership) {
        PageInfo<ElectiveCourseVo> courseVoPageInfo = teachingClassService.findByPageByOwnership(ownership, pageNum, pageSize);
        return Result.build(courseVoPageInfo, ResultCodeEnum.SUCCESS);
    }

    @Log(title = "选课", businessType = 1, operatorType = OperatorType.STUDENT)
    @Operation(summary = "选课")
    @PostMapping(value = "/studentsCourseSelection/{teachingClassId}/{studentNumber}")
    public Result studentsCourseSelection(@PathVariable(value = "teachingClassId") Long teachingClassId,
                                          @PathVariable(value = "studentNumber") String studentNumber) {
        teachingClassService.studentsCourseSelection(teachingClassId, studentNumber);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Log(title = "退选", businessType = 3, operatorType = OperatorType.STUDENT)
    @Operation(summary = "退选")
    @DeleteMapping(value = "/studentsCourseDelete/{teachingClassId}/{studentNumber}")
    public Result studentsCourseDelete(@PathVariable(value = "teachingClassId") Long teachingClassId,
                                       @PathVariable(value = "studentNumber") String studentNumber) {
        teachingClassService.gradeDelete(teachingClassId, studentNumber);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Log(title = "查询已选课程", businessType = 0, operatorType = OperatorType.STUDENT)
    @Operation(summary = "查询已选课程")
    @GetMapping(value = "/getElectiveCourse/{studentNumber}")
    public Result getElectiveCourse(@PathVariable(value = "studentNumber") String studentNumber) {
        List<ElectiveCourseVo> electiveCourseVoList = teachingClassService.getElectiveCourse(studentNumber);
        return Result.build(electiveCourseVoList, ResultCodeEnum.SUCCESS);
    }

}
